package net.dl.ss.dao;

import java.io.Serializable;
import java.util.List;

/**
 * @author yakovlev.yuriy@gmail.com
 * @since 1.9.2008
 */
public interface CommonDaoInterface {
    /**
     * Common interface for all dao purposed to save entity if its identifier equals null
     *
     * @param entity entity object which will be made persistent
     * @return same entity populated with newly created identifier
     */
    public <T> T saveEntity(final T entity);

    /**
     * Common interface for all dao purposed to populate instantiated entity by its identifier
     *
     * @param object entity object which will be populated from persistent storage
     * @param id identifier of persisted object
     * @return loaded object with populated attributes
     */
    public <T> T load(T object, Serializable id);

    /**
     * Common interface for all dao purposed to instantiate entity given identifier for selection
     *
     * @param c class description of persisted object
     * @param id identifier value of persisted object
     * @return newly instantiated entity
     */
    public <T> T get(Class<T> c, Serializable id);

    /**
     * Common interface for all dao purposed to update entity if its identifier doesn't equal null
     *
     * @param entity object which will be synchronized with database
     */
    public void updateEntity(Object entity);

    /**
     * Common interface for all dao purposed to delete entity if its identifier doesn't equal null.
     * But entity still stay transient and could be reused for different purposes
     *
     * @param entity object which will be deleted and made transient
     */
    public void deleteEntity(Object entity);

    /**
     * Common interface for all dao purposed to delete row from database by identifier.
     *
     * @param id value of persistent object identifier
     */
    public void deleteEntityById(Long id);

    /**
     * Common interface to retrieve all entities from specific table or set of tables.
     * Should be carefully and rarely used!!!
     *
     * @param c class of objects wich will be retrieved
     * @return the list of entities
     */
    public <T> List<T> list(Class<T> c);

}
